package com.yanqu.road.server.cmd.activity.fivehero;

import com.yanqu.road.entity.activity.fivehero.FiveHeroConfig;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.FiveHeroProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.fivehero.FiveHeroMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.string.StringUtils;

@Cmd(code = GameProtocol.S_FIVEHERO_NOTIFY_EVENT_DEAL, desc = "")
public class CrossFiveHeroNotifyEventDealCmd extends AbstractCommand {

    private FiveHeroProto.FiveHeroCityDoItRespMsg reqMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        reqMsg = FiveHeroProto.FiveHeroCityDoItRespMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        FiveHeroConfig config = FiveHeroMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        if(!StringUtils.isNullOrEmpty(reqMsg.getPvp().getAttReward())){
            player.getModule(CurrencyModule.class).addCurrency(reqMsg.getPvp().getAttReward(), eLogMoneyType.FiveHero,eLogMoneyType.FiveHeroEventPvpAttReward);
        }
        if(!StringUtils.isNullOrEmpty(reqMsg.getPvp().getRobReward())){
            player.getModule(CurrencyModule.class).addCurrency(reqMsg.getPvp().getRobReward(), eLogMoneyType.FiveHero,eLogMoneyType.FiveHeroEventPvpRobReward);
        }
        if(!StringUtils.isNullOrEmpty(reqMsg.getBandit().getAttReward())){
            player.getModule(CurrencyModule.class).addCurrency(reqMsg.getBandit().getAttReward(), eLogMoneyType.FiveHero,eLogMoneyType.FiveHeroEventBanditAttReward);
        }
        if(!StringUtils.isNullOrEmpty(reqMsg.getBandit().getKillReward())){
            player.getModule(CurrencyModule.class).addCurrency(reqMsg.getBandit().getKillReward(), eLogMoneyType.FiveHero,eLogMoneyType.FiveHeroEventBanditKillReward);
        }
        if(!StringUtils.isNullOrEmpty(reqMsg.getLuoyang().getAttReward())){
            player.getModule(CurrencyModule.class).addCurrency(reqMsg.getLuoyang().getAttReward(), eLogMoneyType.FiveHero,eLogMoneyType.FiveHeroEventLuoYangAttReward);
        }
        if(!StringUtils.isNullOrEmpty(reqMsg.getLuoyang().getWinReward())){
            player.getModule(CurrencyModule.class).addCurrency(reqMsg.getLuoyang().getWinReward(), eLogMoneyType.FiveHero,eLogMoneyType.FiveHeroEventLuoYangKillReward);
        }
        //退元宝的，元宝打怪
        if(!StringUtils.isNullOrEmpty(reqMsg.getReward())){
            player.getModule(CurrencyModule.class).addCurrency(reqMsg.getReward(), eLogMoneyType.FiveHero,eLogMoneyType.FiveHeroAttackLuoYangCostReBack);
        }
        player.sendPacket(ClientProtocol.U_FIVEHERO_EVENT_DEAL,reqMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret == 0) {
            return;
        }
    }
}
